package com.mixsmart.commonweb.bean.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import com.mixsmart.commonweb.bean.ISelfClassAssert;
import com.mixsmart.enums.YesNoType;
import com.mixsmart.utils.StringUtils;

/**
 * 数据字典实体类
 * @author lmq
 * @version 1.0
 * @since JDK版本大于等于1.6
 * 2016年2月1日
 */
@Entity
@Table(name="t_c_dict")
public class TCDict implements ISelfClassAssert<TCDict> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4014331741743357862L;

	private String id;
	
	private String name;
	
	private String strValue;
	
	private Integer intValue;
	
	private String parentId;
	
	private Integer state = YesNoType.YES.getIndex();
	
	/**
	 * 排序
	 */
	private Integer sortNum = 0;
	
	/**
	 * 层级
	 */
	private Integer level = 0;
	
	/**
	 * 是否叶子节点
	 */
	private Boolean isLeaf = true;

	public TCDict() {
	}

	public TCDict(String name, String strValue, String parentId, Integer state,
			Integer sortNum, Integer level, Boolean isLeaf) {
		this.name = name;
		this.strValue = strValue;
		this.parentId = parentId;
		this.state = state;
		this.sortNum = sortNum;
		this.level = level;
		this.isLeaf = isLeaf;
	}

	@Id
	@Column(name="id", length=50)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name="name", length=127, nullable=false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name="str_value", length=127, nullable=false)
	public String getStrValue() {
		return strValue;
	}

	public void setStrValue(String strValue) {
		this.strValue = strValue;
	}
	
	@Column(name="int_value")
	public Integer getIntValue() {
		if(null == intValue) {
			if(StringUtils.isInteger(strValue.trim())) {
				intValue = Integer.parseInt(strValue.trim());
			}
		}
		return intValue;
	}

	public void setIntValue(Integer intValue) {
		this.intValue = intValue;
	}

	@Column(name="parent_id", length=50)
	public String getParentId() {
		return parentId;
	}

	public void setParentId(String parentId) {
		this.parentId = parentId;
	}

	@Column(name="state", length=2)
	public Integer getState() {
		if(null == state) {
			state = YesNoType.YES.getIndex();
		}
		return state;
	}

	@Column(name="state")
	public void setState(Integer state) {
		this.state = state;
	}

	@Column(name="sort_num", nullable=false)
	public Integer getSortNum() {
		return sortNum;
	}

	public void setSortNum(Integer sortNum) {
		this.sortNum = sortNum;
	}

	@Column(name="level_", nullable=false)
	public Integer getLevel() {
		return level;
	}

	public void setLevel(Integer level) {
		this.level = level;
	}

	@Column(name="is_leaf")
	public Boolean getIsLeaf() {
		return isLeaf;
	}

	public void setIsLeaf(Boolean isLeaf) {
		this.isLeaf = isLeaf;
	}

	@Override
	public void assertValue(TCDict dict) {
		if(null != dict) {
			this.name = dict.getName();
			this.parentId = dict.getParentId();
			this.sortNum = dict.getSortNum();
			this.level = dict.getLevel();
			this.state = dict.getState();
			this.strValue = dict.getStrValue();
			this.intValue = dict.getIntValue();
		}
	}
}
